package com.lancoo.znbkxx.fragments;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.example.znbk.znbklibrary.widget.CircleImageView;
import com.example.znbk.znbklibrary.widget.GlideCircleWithBorder;
import com.lancoo.cpbase.authentication.activities.LoginActivity;
import com.lancoo.cpbase.authentication.base.LoginOperate;
import com.lancoo.znbkxx.R;
import com.lancoo.znbkxx.beans.UserInfoBean;
import com.lancoo.znbkxx.uis.MyCollectActivity;
import com.lancoo.znbkxx.uis.MyNoteActivity;

/**
 * Create by TangJun on 2019/2/16
 */
public class PersonalCenterFragment extends Fragment implements View.OnClickListener{
    private CircleImageView mCIvStuHead;
    private TextView mTvStuName,mTvStuClass;
    private RelativeLayout rvNote;
    private RelativeLayout rvCollect;
    private FrameLayout flExit;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_personal, container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        findViews(view);
    }

    private void findViews(View view) {
        mCIvStuHead = view.findViewById(R.id.civ_head);
        Glide.with(this).load(UserInfoBean.PhotoPath).apply(new RequestOptions()
                        .error(this.getResources().getDrawable(R.mipmap.ic_lancoo_launcher))
                        .placeholder(R.mipmap.ic_lancoo_launcher).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL)
                        .transform(new GlideCircleWithBorder(getActivity(), 3, Color.parseColor("#ccffffff")))).into(mCIvStuHead);
        mTvStuName = view.findViewById(R.id.tv_stuName);
        mTvStuName.setText(UserInfoBean.UserName);
        mTvStuClass = view.findViewById(R.id.tv_stuClass);
        mTvStuClass.setText(UserInfoBean.GroupName);
        rvNote = view.findViewById(R.id.rv_note);
        rvCollect = view.findViewById(R.id.rv_collect);
        flExit = view.findViewById(R.id.fl_exit);
        flExit.setOnClickListener(this);
        rvNote.setOnClickListener(this);
        rvCollect.setOnClickListener(this);

    }

    private LoginOperate mLoginOperate = null;
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rv_note:
                getActivity().startActivity(MyNoteActivity.getInstance());
                break;
            case R.id.rv_collect:
                getActivity().startActivity(MyCollectActivity.getInstance());
                break;
            case R.id.fl_exit:
//                getActivity().finish();
                mLoginOperate = new LoginOperate(getActivity());
                mLoginOperate.logOut();
                startActivity(new Intent(getActivity(),LoginActivity.class));
                getActivity().finish();
                break;
        }
    }
}
